import { Suspense } from "react";
import { Redirect, Route, Switch } from "react-router-dom";

const RouterView = (props) => {
  let { routes } = props; 
  return (
    <Suspense fallback={<div></div>}>
      <Switch>
        {routes.map((item, index) => {
          return item.component ? (
            <Route
              key={index}
              path={item.path}
              exact={item.exact}
              render={(props) => {
                return <item.component routes={item.children} {...props} />;
              }}
            ></Route>
          ) : (
            <Redirect key={index} from={item.path} to={item.redirect} />
          );
        })}
      </Switch>
    </Suspense>
  );
};
export default RouterView;
